package edu.nus.mtech.sem1.ca.utils;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.sql.Date;

import javax.swing.JFrame;
import javax.swing.JInternalFrame;

import edu.nus.mtech.sem1.ca.auth.UserRole;


public class Common {
	public static String USER_NAME="";
	public static UserRole USER_ROLE=UserRole.AGENT;
	
	public static void OpenCenterScreen(Object aFrame,boolean aMaximize){
		Toolkit l_tk=Toolkit.getDefaultToolkit();
		Dimension l_dimension=l_tk.getScreenSize();
		int screenheight=l_dimension.height;
		int screenwidth=l_dimension.width;
		
		if(aFrame instanceof JFrame){
			JFrame l_frame=(JFrame)aFrame;
			
			if(aMaximize){
				l_frame.setSize( (int) (screenwidth*0.8), (int)( screenheight*0.8));
			}
			
			l_frame.setLocation((screenwidth - l_frame.getWidth())/2 ,(screenheight- l_frame.getHeight())/2);
			l_frame.setVisible(true);
		}
		else if(aFrame instanceof JInternalFrame){
			JInternalFrame l_frame=(JInternalFrame)aFrame;
			if(l_frame.getParent()!=null){
				screenheight=l_frame.getParent().getHeight();
				screenwidth=l_frame.getParent().getWidth();		
			}
			
			l_frame.setLocation((screenwidth - l_frame.getWidth())/2 ,(screenheight- l_frame.getHeight())/2);
			l_frame.setVisible(true);
		}
			
	}
	public static Date GetDateTime(String aYear,String aMonth,String aday){
		Long l_date=(long) 0;
		String tmp=(aYear.length()<2? "0"+aYear:aYear)+(aMonth.length()<2? "0"+aMonth:aMonth)+(aday.length()<2? "0"+aday:aday);
		l_date= Long.parseLong(tmp);
		Date l_return=new Date(l_date);
		return l_return;
	}
	public static Date GetDateTime(String aDate){
		Long l_date=(long) 0;
		l_date= Long.parseLong(aDate.substring(6, 7)+aDate.substring(3, 4)+aDate.substring(0, 1));
		Date l_return=new Date(l_date);
		return l_return;
	}

}
